package com.example.login;

//import cn.dsna.util.images.ValidateCode;

//import cn.dsna.util.images.ValidateCode;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author mucd
 * 2021年06月21日  9:39
 */

@WebServlet(value = "/VCode")
public class Vcode extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("image/jpeg");
        resp.setHeader("Pragma","no-cache");
        resp.setHeader("Cache-Control","no-cache");
        resp.setDateHeader("Expires",0);

        ValidateCode validateCode = new ValidateCode(130,40,4,50);
        validateCode.write(resp.getOutputStream());
        System.out.println(validateCode.getCode());
        System.out.println("onload");
        HttpSession session = req.getSession();
        session.setAttribute("vcode",validateCode.getCode());
        System.out.println("验证码 = "+validateCode.getCode());
        System.out.println("先执行这个");
    }
}